import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class ServerSocketThread extends Thread {
    private Socket socket;
    List<String> tmpList;

    public ServerSocketThread(Socket s, List<String> strList){
        socket = s;
        tmpList = strList;
    }

    @Override
    public void run(){
        BufferedReader bufferedReader = null;
        PrintStream printStream = null;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while(true){
                String strfromclient = bufferedReader.readLine();
                System.out.println("服务端接收客户端的字符串内容是：" + strfromclient);
                tmpList.add(strfromclient);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null != printStream){
                printStream.close();
            }
            if(null != bufferedReader){
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(null != socket){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
